﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Globalization;
using HA.ModFlow.Domain.DomainLayer;
using HA.ModFlow.Infrastructure;

namespace HA.ModFlow.Controls.Windows
{
    /// <summary>
    /// winUnits.xaml 的交互逻辑
    /// </summary>
    public partial class winUnits : Window
    {
        public winUnits(ModelOption option)
        {
            InitializeComponent();
            this._mdOption =(ModelOption)option.Clone();


            Binding bindLength = new Binding();
            bindLength.Source = this._mdOption.Units;
            bindLength.Path = new PropertyPath("Length");
            bindLength.Converter = new LengthToIntConverter();
            this.cbLength.SetBinding(ComboBox.SelectedIndexProperty,bindLength);

            Binding bindTime = new Binding();
            bindTime.Source = this._mdOption.Units;
            bindTime.Path = new PropertyPath("Time");
            bindTime.Converter = new TimeToIntConverter();
            this.cbTime.SetBinding(ComboBox.SelectedIndexProperty, bindTime);
        }

        ModelOption _mdOption;

        public ModelOption MdOption
        {
            get { return _mdOption; }
            set { _mdOption = value; }
        }


        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

    }

    public class LengthToIntConverter : IValueConverter
    {
        public object Convert(object value,Type targetType,object parameter,CultureInfo culture)
        {
            return (int)value;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            LENGTH et = (LENGTH)value;
            return et;
        }
    }

    public class TimeToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (int)value;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            TIME et = (TIME)value;
            return et;
        }
    }
}
